package com.gack.business.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.gack.business.service.StoreCameraServiceInterface;
import com.gack.helper.common.AjaxJson;
import com.gack.helper.common.abstractobj.ApiController;

import io.swagger.annotations.ApiOperation;

/**
 * 
* @ClassName: StoreCamerasController 
* @Description: TODO(这里用一句话描述这个类的作用) 
* @author (ZhangXinYu)  
* @date 2018年7月10日 下午5:56:19 
* @version V1.0
 */
@RestController
@RequestMapping(ApiController.STORE_CAMERA_URL)
public class StoreCamerasController {
	
	@Autowired
	private StoreCameraServiceInterface cameraService;
	
	@ApiOperation(value="查询没有配置摄像头的门店",notes="查询没有配置摄像头的门店")
	@PostMapping("/getNoCameraStores")
	public AjaxJson getNoCameraStores(String cameraId,String province,String city,String area){
		AjaxJson ajaxJson = new AjaxJson();
		try{
			ajaxJson.setStatus(200).setSuccess(true).setMsg("操作成功").setData(cameraService.getNoCameraStores(cameraId, province, city, area));
		}catch (Exception e) {
			e.printStackTrace();
			ajaxJson.setStatus(500).setSuccess(false).setMsg("操作失败");
		}
		return ajaxJson;
	}
	
	@ApiOperation(value="添加/修改摄像头",notes="添加/修改新摄像头")
	@PostMapping("/addOrUpdate")
	public AjaxJson addOrUpdate(String backid,String id,String storeId,String chineseName,String meetingRoomId,
			@RequestParam(name="type",defaultValue="1")Integer type,String ip){
		AjaxJson ajaxJson = new AjaxJson();
		try{
			ajaxJson.setStatus(200).setSuccess(true).setMsg("操作成功").setData(cameraService.addOrUpdate(backid,id, storeId, chineseName, meetingRoomId, type, ip));
		}catch (Exception e) {
			e.printStackTrace();
			ajaxJson.setStatus(500).setSuccess(false).setMsg("操作失败");
		}
		return ajaxJson;
	}
	
	@ApiOperation(value="摄像头列表",notes="摄像头列表")
	@PostMapping("getCameras")
	public AjaxJson getCameras(String province, String city, String area, String storeName,String chineseNmae,Integer page,Integer size){
		AjaxJson ajaxJson = new AjaxJson();
		try{
			ajaxJson.setStatus(200).setSuccess(true).setMsg("操作成功").setData(cameraService.getCameras(province, city, area, storeName, chineseNmae, page, size));
		}catch (Exception e) {
			e.printStackTrace();
			ajaxJson.setStatus(500).setSuccess(false).setMsg("操作失败");
		}
		return ajaxJson;
	}
	
	@ApiOperation(value="摄像头详情",notes="摄像头详情")
	@PostMapping("getCameraInfo")
	public AjaxJson getCameraInfo(String id){
		AjaxJson ajaxJson = new AjaxJson();
		try{
			ajaxJson.setStatus(200).setSuccess(true).setMsg("操作成功").setData(cameraService.getCameraInfo(id));
		}catch (Exception e) {
			e.printStackTrace();
			ajaxJson.setStatus(500).setSuccess(false).setMsg("操作失败");
		}
		return ajaxJson;
	}
	
	@ApiOperation(value="删除摄像头",notes="删除摄像头")
	@PostMapping("dealCamera")
	public AjaxJson dealCamera(String backid,String id){
		AjaxJson ajaxJson = new AjaxJson();
		try{
			ajaxJson.setStatus(200).setSuccess(true).setMsg("操作成功").setData(cameraService.dealCamera(backid,id));
		}catch (Exception e) {
			e.printStackTrace();
			ajaxJson.setStatus(500).setSuccess(false).setMsg("操作失败");
		}
		return ajaxJson;
	}
}
